<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./js/promiseAjax.js"></script>
</head>
<body>
    <form action="">
        用户名 <input type="text" name="username">
        <br>
        密码 <input type="password" name="password" >
        <br>
        email <input type="email" name="email" >
        <br>
        <input type="submit" >

    </form>
</body>

<script>
    document.querySelector('form').onsubmit=function(){
        var username=document.querySelector('[name="username"]').value
        var password=document.querySelector('[name="password"]').value
        var email=document.querySelector('[name="email"]').value
        request({
            url:'/api/users/register',
            method:'post',
            data:{
                username,
                password,
                email
            }
        }).then(res=>{
            // console.log(res)
            //解构
            var {error_code,msg}=res
            alert(msg)
            if(error_code===0){
                location.href='./login.html'
                // console.log(111)
            }
        })





        //阻止默认行为
        return false
    }



</script>
</html>